package com.example.custom.boot.starter.service;

import com.example.custom.boot.starter.config.FruitConfig;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author duanqichao
 * date: 2021/01/15 1:27
 */

public class FruitService {
    private FruitConfig fruitConfig;
    private final static Logger logger = LoggerFactory.getLogger(FruitService.class);

    public FruitService(FruitConfig fruitConfig) {
        this.fruitConfig = fruitConfig;
    }

    public String showFruitJsonString() {
        ObjectMapper mapper = new ObjectMapper();
        try {
            return mapper.writeValueAsString(this.fruitConfig);
        } catch (JsonProcessingException e) {
            logger.error(e.getMessage());
        }
        return null;
    }
}
